﻿@namespace SE.PO.CInterface.Web.Pages.DB.Device
@page "/db/devices"
@using SE.PO.CInterface.Web.Clients
@using SE.PO.CInterface.DBProtocols.Devices
@using SE.PO.CInterface.Enums
@inject DeviceClient Client
@using SE.PO.CInterface.Web.Pages.DB.Components
@inject INotificationService Notice
<PageContainer Title="设备">
    <Breadcrumb>
        <Breadcrumb>
            <BreadcrumbItem>首页</BreadcrumbItem>
            <BreadcrumbItem>数据库协议</BreadcrumbItem>
            <BreadcrumbItem>设备</BreadcrumbItem>
        </Breadcrumb>
    </Breadcrumb>
    <Content>
        <span>下级SC把监控对象配置根据“数据库接口定义”的数据结构存储到中间数据库表中，增加、修改和删除任何配置，下级SC必须保证能够及时的维护该中间数据库表中的数据。涉及到的中间数据库表有M_Area、M_Site、M_Device、M_Device、M_SIGNAL，M_Device，NodeModify，NodeUpdate。中间数据库表中的数据除了NodeUpdate外均由下级SC维护，下级SC保证上述表中的数据和下级SC的配置一致；NodeUpdate表由上级SC负责添加数据，下级SC定时获取数据并维护（删除）。</span>
    </Content>
    <ChildContent>
        <Card>
            <Button OnClick="@SyncDevices" Type="primary" Style="margin-bottom:16px">
                同步设备
            </Button>
            <Button OnClick="@SyncDevicesAssertId" Type="primary" Icon="@IconType.Outline.FileExcel" Style="margin-bottom:16px">
                上传资管编码表
            </Button>
            <Button OnClick="@DeleteSelectedRows" Type="danger" Style="margin-bottom:16px">
                删除选定
            </Button>
            设备类型：
            <SelectDeviceType @ref="@_selectDeviceTypeComp" SelectDeviceTypeChanged="async (s) => { await GetDeviceSourceByTypeAsync(s); }"></SelectDeviceType>
            <P style="width: 60px;float: right;">共：@_total</P>
            <Table @ref="_table"
                   TItem="DeviceDto"
                   ScrollY="680px"
                   DataSource="@_source"
                   Loading="@_loadingData"
                   Total="_total"
                   @bind-PageIndex="_pageIndex"
                   @bind-PageSize="_pageSize"
                   @bind-SelectedRows="_selectedRows"
                   OnChange="OnChange"
                   Size="TableSize.Small">

                <ColumnDefinitions>
                    <Selection Key="@(context.Id)"/>
                    @* <PropertyColumn Title="下级SCID" Property="c => c.ScId"/> *@
                    <PropertyColumn Title="设备编号" Width="140px" Property="c => c.Id"/>
                    <PropertyColumn Title="监控单元资管编码" Sortable  Property="c => c.DevAssetId"/>
                    <PropertyColumn Title="机房" Property="c => c.RoomRoomName"/>
                    @* <PropertyColumn Title="站点" Property="c => c.SiteSiteName"/> *@
                    @* <PropertyColumn Title="监控单元" Property="c => c.SuId"/> *@
                    <PropertyColumn Width="300" Title="设备名称" Property="c => c.Equipment"/>
                    <PropertyColumn Title="IO" Sortable  Property="c => c.IODevice" />
                    <PropertyColumn Title="设备类型" Property="c => c.DisplayDeviceType"/>
                    @* <PropertyColumn Title="生产厂家描述" Property="c => c.Productor" /> *@
                    @* <PropertyColumn Title="协议版本描述" Property="c => c.Version" /> *@
                    @* <PropertyColumn Title="投入运行时间" Property="c => c.BeginRunTime" /> *@
                    @* <PropertyColumn Title="设备型号" Property="c => c.DeviceModel" /> *@
                    @* <PropertyColumn Title="资源工程状态" Property="c => c.LocateNeStatus" /> *@
                    <ActionColumn Width="160" Title="操作" Fixed="right">
                        <Space>
                            <SpaceItem>
                                <Button Danger OnClick="@(() => { _delVisible = true; Delete(context.Id);})">删 除</Button>
                            </SpaceItem>
                            <SpaceItem>
                                <Button OnClick="@(() => { _editVisible = true; Edit(context.Id);})">修 改</Button>
                            </SpaceItem>
                        </Space>
                    </ActionColumn>
                </ColumnDefinitions>
            </Table>
        </Card>
    </ChildContent>
</PageContainer>

<Modal Title="新增设备"
       Centered="true"
       Width="1024"
       Visible="@_addVisible"
       OnOk="@AddHandleOk"
       OnCancel="@AddHandleCancel">
    <AddDeviceFrom @ref="_addFrom"
                   OnSuccess="async () => { _addVisible = false; await GetSourceAsync(_pageIndex, _pageSize);}"
                   OnFailure="() => { _addVisible = true; }"
                   OnCancel="() => { _addVisible = true; }">
    </AddDeviceFrom>
</Modal>

<Modal Title="同步设备"
       Centered="true"
       Visible="@_syncVisible"
       Width="1440"
       MaxBodyHeight="@("80vh")"
       OnOk="@SyncHandleOk"
       OnCancel="@SyncHandleCancel">
    <SyncDeviceFrom @ref="_syncFrom"
                    OnSuccess="async () => { _syncVisible = false; await GetSourceAsync(_pageIndex, _pageSize);}"
                    OnFailure="() => { _syncVisible = true; }"
                    OnCancel="() => { _syncVisible = true; }">
    </SyncDeviceFrom>
</Modal>

<Modal Title="编辑设备"
       Centered="true"
       Width="1024"
       Visible="@_editVisible"
       OnOk="@EditHandleOk"
       OnCancel="@EditHandleCancel">
    <EditDeviceFrom @ref="_editFrom"
                    Model="@_editModel"
                    OnSuccess="async () => { _editVisible = false; await GetSourceAsync(_pageIndex, _pageSize);}"
                    OnFailure="() => { _editVisible = true; }"
                    OnCancel="() => { _editVisible = true; }">
    </EditDeviceFrom>
</Modal>

<Modal Title="删除设备"
       Centered="true"
       Visible="@_delVisible"
       OnOk="@DeleteHandleOk"
       OnCancel="@DeleteHandleCancel">
    <DelDeviceFrom @ref="_delFrom"
                   Model="DelModel"
                   Models="@DelModels"
                   OnSuccess="async () => { _delVisible = false; await GetSourceAsync(_pageIndex, _pageSize);}"
                   OnFailure="() => { _delVisible = true; }"
                   OnCancel="() => { _delVisible = true; }">
    </DelDeviceFrom>
</Modal>